package cn.mw.cmdb.param;

import com.alibaba.nacos.common.utils.CollectionUtils;
import com.google.common.base.Strings;
import lombok.Data;
import org.springframework.data.annotation.Transient;

import java.util.ArrayList;
import java.util.List;

/**
 * 资产监控基础参数
 */
@Data
public class QueryMonitorParam extends CustomPageParam implements QueryMonitorValue {
    @Transient
    private String instanceId;
    @Transient
    private String instanceName;
    @Transient
    private String modelId;
    @Transient
    private String mwEngineSource;
    //监控轮询引擎类型
    @Transient
    private Integer mwProxyType;
    //监控轮询引擎id
    @Transient
    private String mwProxyId;
    @Transient
    private Integer monitorServerId;
    @Transient
    private String hostId;
    @Transient
    private List<String> hostIds;
    @Transient
    private List<String> itemIds;
    @Transient
    private String monitorType;
    //监控资产主模板Id
    @Transient
    private String templateId;
    @Transient
    private String templateName;
    //监控资产套用的所有模板Id
    @Transient
    private List<String> templateIds;
    @Transient
    //自动发现规则Ids
    private List<String> discoveryIds;

    @Transient
    //item中valuemapid属性
    private List<String> valuemapIds;

    @Transient
    private List<Long> users;
    @Transient
    private List<List<Long>> orgs;
    @Transient
    private List<Long> groups;

    @Transient
    private List<String> path;

    @Override
    public List<String> getHostIds() {
        if (!Strings.isNullOrEmpty(hostId) && CollectionUtils.isEmpty(hostIds)) {
            hostIds = new ArrayList<>();
            hostIds.add(hostId);
        }
        return hostIds;
    }

    @Override
    public String getTemplateId() {
        String templateIdVal = templateId;
        boolean isFlag = Strings.isNullOrEmpty(templateId) || "0".equals(templateId);
        if(isFlag && CollectionUtils.isNotEmpty(templateIds)){
            templateIdVal = templateIds.get(0);
        }
        return templateIdVal;
    }
}
